<?php

namespace App\Admin\Controllers;

use App\Models\Baoming;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class BaomingController extends Controller
{
    use ModelForm;

    const header = '报名表单';
    const description = '';

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header(self::header);
            $content->description(self::description);

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header(self::header);
            $content->description(self::description);

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header(self::header);
            $content->description(self::description);

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Baoming::class, function (Grid $grid) {

            $grid->id('ID')->sortable();

            $grid->column('relname', '参赛者');
            $grid->column('age', '主唱年龄');
            $grid->column('mobile', '联系方式');
            $grid->column('source', '知晓途径');

            $grid->column('type', '参赛方式')->display(function ($val) {

                if ($val == 1) {
                    return '<span class="badge bg-orange">个人</span>';
                } else {
                    return '<span class="badge bg-green">组合</span>';
                }
            });

            $grid->created_at(trans('admin::lang.created_at'));
//            $grid->updated_at(trans('admin::lang.updated_at'));


            $grid->column('isread', '已读')->switch(Baoming::$readed);

            $grid->disableCreation();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(Baoming::class, function (Form $form) {

            $form->display('id', 'ID');

            $form->radio('type', '报名类型')->values(['1' => '个人', '2' => '组合'])->default('1');


            $form->text('relname', '参赛者1');
            $form->text('age', '主唱年龄');
            $form->text('relname2', '参赛者2');
            $form->text('relname3', '参赛者3');

            $form->divide();

            $form->text('song', '参赛曲目');
            $form->radio('yuanchuang', '原创')->values(['1' => '原创', '0' => '非原创'])->default('1');
            $form->text('video', '视频链接');
            $form->text('mobile', '联系方式');
            $form->email('email', 'EMAIL');

            $form->text('source', '知晓途径');
            $form->display('created_at', trans('admin::lang.created_at'));
            $form->display('updated_at', trans('admin::lang.updated_at'));


            $form->disableReset();
            $form->disableSubmit();
        });
    }
}
